#!/bin/bash

# ============================================
# 强制更新 Git 仓库（覆盖本地修改）
# ============================================

set -e

REPO_PATH="/mnt/lwy/django-vue3-admin"

echo "=== 强制更新 Git 仓库 ==="
echo ""

cd "$REPO_PATH"

# 1. 备份当前 .env.production（如果需要）
if [ -f "web/.env.production" ]; then
    echo "备份当前 .env.production..."
    cp web/.env.production web/.env.production.backup.$(date +%Y%m%d_%H%M%S)
    echo "✓ 备份完成"
fi

# 2. 暂存本地修改
echo ""
echo "暂存本地修改..."
git stash save "Local changes before pull - $(date +%Y%m%d_%H%M%S)" || echo "无需暂存"

# 3. 拉取更新
echo ""
echo "拉取远程更新..."
git pull

# 4. 显示更新日志
echo ""
echo "=== 最近的更新 ==="
git log --oneline -5

echo ""
echo "=== 文件状态 ==="
git status

echo ""
echo "✓ 更新完成！"
echo ""
echo "如果需要恢复备份的 .env.production:"
echo "  cp web/.env.production.backup.* web/.env.production"

